import openpyxl
import json
import os


def get_device():
    """获取当前连接设备的device"""
    a = os.popen('adb devices')
    text1 = a.read()
    device = text1.split(' ')[3].splitlines()[1].split()[0]
    # device = '\''+device+'\''
    a.close()
    return device


def get_android():
    """获取当前连接设备的安卓版本"""
    b = os.popen('adb shell getprop ro.build.version.release')
    text2 = b.read()
    android = text2.split()[0]
    androids = '\''+android+'\''
    b.close()
    return androids


def xlsx_to_json(file_path):
    # 加载xlsx文件
    workbook = openpyxl.load_workbook(file_path)
    sheet = workbook.active
    headers = [cell.value for cell in sheet[1]]
    # 创建一个空列表来保存数据行
    data_rows = []
    # 从第二行开始遍历数据行
    for row in sheet.iter_rows(min_row=2, values_only=True):
        # 创建一个字典，其中键是列标题，值是对应的数据
        data_row = dict(zip(headers, row))
        data_rows.append(data_row)
        # 将数据行列表转换为json字符串
    json_data = json.dumps(data_rows, indent=4, ensure_ascii=False)
    return json_data



